package com.itita.ww2.handler.requesthandler.basemap;

import java.sql.SQLException;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.itita.ww2.core.WW2Exception;
import com.itita.ww2.utils.handler.IRequestOper;

/**
 * 地图防御建筑升级完成
 * @author NorthLan
 *
 */
public class MapDefUpgradeComplete implements IRequestOper {

	@Override
	public boolean execute(String requestCMD, User user, ISFSObject params) throws WW2Exception, SQLException {
		//		UserProfile userProfile = UserService.getInstance().getUserProfile(user);
		//		int uid = userProfile.getUid();
		//		//
		//		ISFSObject backObj = new SFSObject();
		//		backObj.putInt(R.DATA_KEY_COUNTER, params.getInt(R.DATA_KEY_COUNTER));
		//		//
		//		String key = params.getUtfString("devKey");
		//		String mapCode = DevKeyUtil.splitKey(key, 1);
		//
		//		// 当前是否在升级态
		//		if (!UserService.getInstance().haveTime(uid, DevTimeType.UPGRADE, mapCode)) {
		//			MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, MsgCode.BASEMAP_UNIT_NOT_UPGRADING, false);
		//			return false;
		//		}
		//
		//		// 时间是否已经达到
		//		if (!UserService.getInstance().isDevEndTime(uid, key)) {
		//			MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, MsgCode.TIME_HAS_NOT_ARRIVED, false);
		//			return false;
		//		}
		//
		//		// 该单位是否还在地图上
		//		ISFSObject userMapdata = UserService.getInstance().getUserMapdata(uid);
		//		if (!userMapdata.containsKey(mapCode)) {
		//			return false;
		//		}
		//		ISFSObject mapUnit = userMapdata.getSFSObject(mapCode);
		//		String bdCode = BaseMapUtil.getBuildCode(mapUnit);
		//
		//		// 升级防御建筑
		//		int newLevel = UserService.getInstance().mapUnitLevelOper(uid, mapCode, 1);
		//		// 移除升级时间
		//		UserService.getInstance().removeDevTime(uid, key);
		//		// 用户涨经验
		//		UserService.getInstance().growthUserExpOfBLL(userProfile, bdCode);
		//		// 推消息
		//		ISFSObject pushObj = new SFSObject();
		//		pushObj.putUtfString("key", key);
		//		pushObj.putUtfString("code", mapCode);
		//		pushObj.putInt("level", newLevel);
		//		MessageHandler.getInstance().pushMsg(PushCode.GAME_DEFENCE_UPGRADE_COMPLETE, pushObj, user);
		//		// 
		//		MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, null, true);
		return true;
	}

}
